package com.hongxun.modules.eys.service.impl;

import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.eys.dao.ECrossCostDao;
import com.hongxun.modules.eys.entity.ECrossCostEntity;
import com.hongxun.modules.eys.service.ECrossCostService;



@Service("eCrossCostService")
public class ECrossCostServiceImpl implements ECrossCostService {
	@Autowired
	private ECrossCostDao eCrossCostDao;
	
	@Override
	public ECrossCostEntity queryObject(String guid){
		return eCrossCostDao.queryObject(guid);
	}
	
	@Override
	public List<ECrossCostEntity> queryList(Map<String, Object> map){
		return eCrossCostDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return eCrossCostDao.queryTotal(map);
	}
	
	@Override
	public void save(ECrossCostEntity eCrossCost){
        if(eCrossCost.getGuid()==null||eCrossCost.getGuid().equals("")) {

		    eCrossCost.setGuid(UUID.randomUUID().toString());
        }
		eCrossCostDao.save(eCrossCost);
	}
	
	@Override
	public void update(ECrossCostEntity eCrossCost){
		eCrossCostDao.update(eCrossCost);
	}
	
	@Override
	public void delete(String guid){
		eCrossCostDao.delete(guid);
	}
	
	@Override
	public void deleteBatch(String[] guids){
		eCrossCostDao.deleteBatch(guids);
	}

	@Override
	public void insertOrReplaceOrDelete(List<ECrossCostEntity> entities) {
		for (ECrossCostEntity d : entities) {
			if (d.getCCDatastate().equals("删除")) {
				eCrossCostDao.delete(d.getGuid());
			} else {
				ECrossCostEntity eCrossCostEntity = eCrossCostDao.queryObject(d.getGuid());
				if (eCrossCostEntity == null) {
					eCrossCostDao.save(d);
				} else {
					eCrossCostDao.update(d);
				}
			}
		}
	}
	
}
